//
// HDCommonH.h
// HDWuDaDaoServiceCenter
//
// Created by HDNiuKuiming on 2017/4/7.
// Copyright © 2017年 HDNiuKuiming. All rights reserved.
//

#ifndef HDCommonH_h
#define HDCommonH_h


// 方法的定义，为空判断
#define kStringIsEmpty(str) ([str isKindOfClass:[NSNull class]] \
|| str == nil || [str length] < 1 ? YES : NO ) // 字符串是否为空

#define kArrayIsEmpty(array) (array == nil \
|| [array isKindOfClass:[NSNull class]] || array.count == 0) // 数组是否为空

#define kDictIsEmpty(dic) (dic == nil \
|| [dic isKindOfClass:[NSNull class]] || dic.allKeys == 0)// 字典是否为空

#define kObjectIsEmpty(_object) (_object == nil \
|| [_object isKindOfClass:[NSNull class]] \
|| ([_object respondsToSelector:@selector(length)] && [(NSData *)_object length] == 0) \
|| ([_object respondsToSelector:@selector(count)] && [(NSArray *)_object count] == 0))// 是否是空对象


#define ScreenWidth [UIScreen mainScreen].bounds.size.width
#define ScreenHeight [UIScreen mainScreen].bounds.size.height
#define STATUSBAR_HEIGHT ([UIApplication sharedApplication].statusBarFrame.size.height)

#define BACK(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)
#define MAIN(block) dispatch_async(dispatch_get_main_queue(),block)
#define USER_DEFAULT [NSUserDefaults standardUserDefaults] // NSUserDefaults 实例化

//一些常用的缩写
#define kApplication [UIApplication sharedApplication]
#define kKeyWindow [UIApplication sharedApplication].keyWindow
#define kAppDelegate [UIApplication sharedApplication].delegate
#define kUserDefaults [NSUserDefaults standardUserDefaults]
#define kNotificationCenter [NSNotificationCenter defaultCenter]


// App相关的信息
#define kAppVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] // APP版本号
#define kSystemVersion [[UIDevice currentDevice] systemVersion] // 系统版本号
#define kCurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])// 获取当前语言
#define kISiPhone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)// 判断是否为iPhone
#define kISiPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) // 判断是否为iPad
#define kIS_Fir_Edition ([[[NSBundle mainBundle] bundleIdentifier] isEqualToString:@"com.hengdawb.HDChengDuJinShaSiteMuseum"]) // 判断是否为fir测试平台

#define kDocumentPath [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] // 获取沙盒Document路径
#define kTempPath NSTemporaryDirectory()// 获取沙盒temp路径
#define kCachePath [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]// 获取沙盒Cache路径


#define kWeakSelf(type) __weak typeof(type) weak##type = type; // 弱引用/
#define kStrongSelf(type) __strong typeof(type) type = weak##type;// 强引用

#define kDegreesToRadian(x) (M_PI * (x) / 180.0) // 由角度转换弧度
#define kRadianToDegrees(radian) (radian * 180.0) / (M_PI)// 由弧度转换角度

// 获取一段时间间隔
#define kStartTime CFAbsoluteTime start = CFAbsoluteTimeGetCurrent();
#define kEndTime NSLog(@"Time: %f", CFAbsoluteTimeGetCurrent() - start)


#define LOAD_IMAGE(file,ext) [UIImage imageWithContentsOfFile:［NSBundle mainBundle]pathForResource:file ofType:ext］// 读取本地图片
#define IMAGE(A) [UIImage imageWithContentsOfFile:［NSBundle mainBundle] pathForResource:A ofType:nil］// 定义UIImage对象
#define ImageNamed(_pointer) [UIImage imageNamed:[UIUtil imageName:_pointer］// 定义UIImage对象


// 颜色的定义
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]// rgb颜色转换（16进制->10进制）
#define COLOR(R, G, B, A) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:A]// 带有RGBA的颜色设置

#define RGBA(r,g,b,a) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]//
#define RGB(r,g,b) RGBA(r,g,b,1.0f) // 获取RGB颜色

#define Bg_Color [UIColor colorWithRed:242.0/255.0 green:236.0/255.0 blue:231.0/255.0 alpha:1.0]// 背景色
#define Text_Color [UIColor colorWithRed:75.0f/255.0f green:42.0f/255.0f blue:25.0f/255.0f alpha:1.0f]
#define Common_Color [UIColor colorWithRed:225.0f/255.0f green:188.0f/255.0f blue:109.0f/255.0f alpha:1.0f]

#define Common_Light_Gray_Color [UIColor colorWithRed:240.0f/255.0f green:240.0f/255.0f blue:240.0f/255.0f alpha:1.0f]
#define Common_Oringe_Color [UIColor colorWithRed:255.0f/255.0f green:180.0f/255.0f blue:0.0f/255.0f alpha:1.0f]
#define designFont(fontSize) [UIFont fontWithName:@"FZQKBYSJW--GB1-0" size:fontSize] // 设计的字体


// Log宏定义，在debug时输出，在release时不产生输出
#ifdef DEBUG
#define LOG(...) NSLog(__VA_ARGS__);
#define LOG_METHOD NSLog(@"%s", __func__);
#define LOG_CMETHOD NSLog(@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd))
#define COUNT(p) NSLog(@"%s(%d): count = %d\n", __func__, __LINE__, [p retainCount]);
#define LOG_TRACE(x) do {printf x; putchar('\n'); fflush(stdout);} while (0)
#else
#define LOG(...);
#define LOG_METHOD
#define LOG_CMETHOD
#define COUNT(p)
#define LOG_TRACE(x)
#endif

#ifdef DEBUG
#define M_LOG(format, ...) printf("\n[%s] %s [第%d行] %s\n", __TIME__, __FUNCTION__, __LINE__, [[NSString stringWithFormat:format, ## __VA_ARGS__] UTF8String]);
#else
#define M_LOG(format, ...)
#endif


//判断是在真机还是在模拟器上运行
#if TARGET_IPHONE_SIMULATOR
#define SIMULATOR 1
#elif TARGET_OS_IPHONE
#define SIMULATOR 0
#endif


#endif /* HDCommonH_h */
